package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.CmsPrefrenceAreaProductRelationMpper;
import com.mall.pojo.CmsPrefrenceAreaProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class CmsPrefrenceAreaProductRelationApiAmpl implements CmsPrefrenceAreaProductRelationApi {
    @Autowired
    private CmsPrefrenceAreaProductRelationMpper cmsPrefrenceAreaProductRelationMpper;

    //创建商品(八接口之一)
    @Override
    public void create(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList) {
        if (prefrenceAreaProductRelationList != null) {
            for (CmsPrefrenceAreaProductRelation cmsPrefrenceAreaProductRelation : prefrenceAreaProductRelationList) {
                cmsPrefrenceAreaProductRelationMpper.insert(cmsPrefrenceAreaProductRelation);
            }
        }
    }

    //更新商品 更新八张表之一
    @Override
    public void update(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList) {
        if (prefrenceAreaProductRelationList != null) {
            for (CmsPrefrenceAreaProductRelation relation : prefrenceAreaProductRelationList) {
                cmsPrefrenceAreaProductRelationMpper.updateById(relation);
            }
        }
    }

    @Override
    public List<CmsPrefrenceAreaProductRelation> selectById(Integer id) {
        LambdaQueryWrapper<CmsPrefrenceAreaProductRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CmsPrefrenceAreaProductRelation::getProductId, id);
        return cmsPrefrenceAreaProductRelationMpper.selectList(wrapper);
    }
}
